package com.example.sxmall.service.enums;

import com.example.sxmall.service.action.ActionCartService;
import com.example.sxmall.service.action.impl.*;
import lombok.AllArgsConstructor;
import lombok.Getter;

/**
 * @Description: TODO
 * @Author whh-yt
 * @Date 2022/3/8 4:49 下午
 */
@Getter
@AllArgsConstructor
public enum OperateCartEnum {

    DEFAULT             (-99,"查询购物车内容",  ActionCartService.class.getSimpleName()),
    CLEAR               (-1,"清空无效商品",     ClearCartActionService.class.getSimpleName()),
    REMOVE_ALL          (0,"全部删除",         RemoveAllCartActionService.class.getSimpleName()),
    ADD                 (1,"添加单个商品",      AddCartActionService.class.getSimpleName()),

    /**
     * 对商品进行修改购物车商品数量，更改规格等
     */
    UPDATE              (2,"更新",         UpdateCartActionService.class.getSimpleName()),
    CHECK               (3,"勾选",         CheckCartActionService.class.getSimpleName()),
    MORE                (4,"添加多个商品",  MoreCartActionService.class.getSimpleName()),
    REMOVE              (9,"删除",         RemoveCartActionService.class.getSimpleName()),

    ;

    private final Integer type;
    private final String typeName;
    private final String clazz;

    public static OperateCartEnum getEnumByType(Integer type) {
        for (OperateCartEnum operationCartEnum : OperateCartEnum.values()) {
            if (operationCartEnum.getType().equals(type)) {
                return operationCartEnum;
            }
        }
        return null;
    }

    public static OperateCartEnum getEnumByClassName(String className) {
        for (OperateCartEnum operationCartEnum : OperateCartEnum.values()) {
            if (operationCartEnum.getClazz().equals(className)) {
                return operationCartEnum;
            }
        }
        return null;
    }
}
